<!doctype html>
<html>
<head>
	<meta charset="utf-8"><meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>课堂</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
	<style>
		#comments{
			background: #fff;
		}
		#comments li{
			padding:1rem 0 0;
			margin:0 1rem;
			display: block;
		}
		#comments textarea{
			height: 11rem;
			min-height: 11rem;
			max-height: 9rem;
			width: 100%;
			text-align: left;
		}
		#comments #imgs{
			margin:0 1rem 1rem;
		}
		#comments #imgs img{
			float: left;
			display: block;
			margin:.5rem;
			width:7rem;
			height:7rem;
			.radius_a;
			border:1px solid #d6d6d6
		}
		#comment_intros{
			padding:1rem;
		}
		#comment_intros p{
			font-size: 1.1rem;
			color: #888;
			padding:0 0 .5rem;
		}
		#classes{
			padding:1rem 0;
		}
		.app_tags .app_tagstit{
			padding:1rem 0;
			border-top: 1px solid #f6f6f6;
		}
		.app_tags .app_tagstit i{
			color: #888;
			font-size: 75%;
		}
	</style>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<span class="left back"></span>
			<span class="name">发表...</span>
			<span class="right" tapmode onclick="sendComment()">提交</span>
		</div>
		<div class="app_main">
			<div id="nocontent" class="nocontent animated fadeInUp">
				<img src="../../lib/img/loading.gif" class="minimize" alt="">
				<div class="text minimize">
					数据加载中
				</div>
			</div>
			<div id="comment_intros">
				<p>
					请文明用语，并遵守互联网相关政策法规。
				</p>
			</div>
		</div>

	</div>

</div>
<script id="comment_template" type="text/html">

	<%$('.app_head .name').text(actName)%>
	<ul id="comments" class="clearfix">
		<li id="textarea" style="">
			<textarea style="" placeholder="请输入正文..."></textarea>
		</li>
		<%if(act==='circle'){%>
		<li id="imgs" class="clearfix" tapmode onclick="_$.img.getImg({
			max:4,
			call:sendImgs
		})">
			<img src="../../lib/img/addpic.gif">
		</li>
		<li id="classes" class="app_tags clearfix">
			<span class="app_tagstit">分类 <i>（不选择默认为您的艺考方向）</i></span>
			<% for(var i in _classify_){if(i>0){ %>
			<a class="tag" tapmode onclick="setTag(this,<%:=_classify_[i].id %>)" href="javascript:;">
				<%:=_classify_[i].name %>
			</a>
			<% }} %>
		</li>
		<li class="space"></li>
		<%}%>
	</ul>

</script>
<script>
	var
		pageSetting,
		setTag=function(obj,id){
			$('.active').removeClass('active');
			$(obj).addClass('active');
			pageSetting.classify = [id];
		},
		sendImgs=function(imgs){
			var html=[
					'<img src="'+_$.imgCache.default+'" data_src="',
					'" class="imgcache">'
				],
				str='';
			pageSetting.imgs=[];
			for(var i in imgs){
				str+=html[0]+(imgs[i].thumb)+html[1];
				pageSetting.imgs.push(imgs[i].thumb);
			}
			$('#imgs').html(str);
			_$.imgCache.load();
		},
		sendComment=function(){

			$('input,textarea').blur();

			pageSetting.content = $('#textarea textarea').val();

			var ajaxSetting = {
				call: function (data) {
					if (data.status === 200) {
						api.execScript({
							name: pageSetting.actWin,
							frameName:pageSetting.actFrame,
							script: pageSetting.call + '(' + JSON.stringify(data) + ');'
						})
					} else {
						api.toast({
							msg: data.msg
						})
					}
				}
			},
				status=[_$.dataTest('notempty', pageSetting.content),(pageSetting.imgs!==null)]

			if(pageSetting.act==='circle') {

				if(!status[0] && !status[1]){
					api.toast({
						msg: '文字和图片至少需要完善一项'
					});
					return;
				}
				ajaxSetting.interface = 'sendCircle';
				ajaxSetting.data = {
					contentpic:pageSetting.imgs,
					classify:pageSetting.classify,
					content: pageSetting.content
				}

			}else if(pageSetting.act==='replyArtcircle'){

				if(!status[0]){
					api.toast({
						msg: '文字内容未填写'
					});
					return;
				}
				ajaxSetting.interface = 'sendArtcircleMood';
				ajaxSetting.data = {
					act:'comment',
					mid: pageSetting.mid,
					reply_cid: pageSetting.data.cid,
					content: pageSetting.content
				}

			}else{

				if(!status[0]){
					api.toast({
						msg: '文字内容未填写'
					});
					return;
				}

				ajaxSetting.interface = 'getClassComment';
				ajaxSetting.data = {
					mid: pageSetting.mid,
					content: pageSetting.content
				}

			}
			_$.sleep(function(){
				_$.ajax(ajaxSetting);
			},250);
			_$.sleep(function(){
				api.closeWin();
			},500);
		},
		appready = function () {
			pageSetting = api.pageParam;
			console.log(JSON.stringify(pageSetting));
			_$.db.get({
				key: 'classify',
				call: function (data) {
					pageSetting._classify_ = data;
					_$.template('comment_template', pageSetting, function (html) {
						$('#nocontent').replaceWith(html);
					})
				}
			})
		};

</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/swiper.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>